package com.lastproject.ejb.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@NamedQuery(name = "User.findAll", query = "SELECT u from User u")
public class User implements Serializable {

	private static final long serialVersionUID = -3656780294878064220L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;

	private String username;
	private String password;
	private String statusPassword;
	private String firstname;
	private String lastname;
	private String workEmail;
	private boolean enabled;

	@Temporal(TemporalType.DATE)
	private Date dob;
	private String personalPhone;
	private String personalEmail;

	@Temporal(TemporalType.DATE)
	private Date employmentDate;

	@Temporal(TemporalType.DATE)
	private Date departureDate;

	@Temporal(TemporalType.DATE)
	private Date medCheckUpDate;
	private String employmentType;
	private String position;
	@Lob
	private byte[] cv;

	@OneToOne
	@JoinColumn(name = "idTeamLeader")
	private User teamLeader;

	@OneToMany(mappedBy = "user")
	private List<Answer> answers;

	@OneToMany(mappedBy = "user")
	private List<Borrowed> borrowed;

	@OneToMany(mappedBy = "user")
	private List<Sugestion> suggestions;

	@OneToMany(mappedBy = "user")
	private List<Review> reviews;

	@OneToMany(mappedBy = "user")
	private List<Rating> ratings;

	@OneToMany(mappedBy = "user")
	private List<WaitingList> waitingLists;

	@OneToMany(mappedBy = "user")
	private List<Survey> surveys;

//	@ManyToMany(mappedBy = "users")
	@ManyToMany
	@JoinTable(name = "role_users",
	        joinColumns = {@JoinColumn(name = "idUser")},
	        inverseJoinColumns = {@JoinColumn(name = "idRole")})
	private List<Role> roles;

	@ManyToMany(mappedBy = "users")
	private List<EmailGroup> emailGroups;

	public User() {

	}

	public List<Survey> getSurveys() {
		return surveys;
	}

	public void setSurveys(List<Survey> surveys) {
		this.surveys = surveys;
	}

	public List<EmailGroup> getEmailGroups() {
		return emailGroups;
	}

	public void setEmailGroups(List<EmailGroup> emailGroups) {
		this.emailGroups = emailGroups;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getStatusPassword() {
		return statusPassword;
	}

	public void setStatusPassword(String statusPassword) {
		this.statusPassword = statusPassword;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getWorkEmail() {
		return workEmail;
	}

	public void setWorkEmail(String workEmail) {
		this.workEmail = workEmail;
	}

	public Date getDob() {
		return dob;
	}

	public void setDob(Date dob) {
		this.dob = dob;
	}

	public String getPersonalPhone() {
		return personalPhone;
	}

	public void setPersonalPhone(String personalPhone) {
		this.personalPhone = personalPhone;
	}

	public String getPersonalEmail() {
		return personalEmail;
	}

	public void setPersonalEmail(String personalEmail) {
		this.personalEmail = personalEmail;
	}

	public Date getEmploymentDate() {
		return employmentDate;
	}

	public void setEmploymentDate(Date employmentDate) {
		this.employmentDate = employmentDate;
	}

	public Date getDepartureDate() {
		return departureDate;
	}

	public void setDepartureDate(Date departureDate) {
		this.departureDate = departureDate;
	}

	public Date getMedCheckUpDate() {
		return medCheckUpDate;
	}

	public void setMedCheckUpDate(Date medCheckUpDate) {
		this.medCheckUpDate = medCheckUpDate;
	}

	public String getEmploymentType() {
		return employmentType;
	}

	public void setEmploymentType(String employmentType) {
		this.employmentType = employmentType;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public byte[] getCv() {
		return cv;
	}

	public void setCv(byte[] cv) {
		this.cv = cv;
	}

	public User getTeamLeader() {
		return teamLeader;
	}

	public void setTeamLeader(User teamLeader) {
		this.teamLeader = teamLeader;
	}

	public List<Answer> getAnswers() {
		return answers;
	}

	public void setAnswers(List<Answer> answers) {
		this.answers = answers;
	}

	public List<Borrowed> getBorrowed() {
		return borrowed;
	}

	public void setBorrowed(List<Borrowed> borrowed) {
		this.borrowed = borrowed;
	}

	public List<Sugestion> getSuggestions() {
		return suggestions;
	}

	public void setSuggestions(List<Sugestion> suggestions) {
		this.suggestions = suggestions;
	}

	public List<Review> getReviews() {
		return reviews;
	}

	public void setReviews(List<Review> reviews) {
		this.reviews = reviews;
	}

	public List<Rating> getRatings() {
		return ratings;
	}

	public void setRatings(List<Rating> ratings) {
		this.ratings = ratings;
	}

	public List<WaitingList> getWaitingLists() {
		return waitingLists;
	}

	public void setWaitingLists(List<WaitingList> waitingLists) {
		this.waitingLists = waitingLists;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	public void addRoles(Role r) {
		roles.add(r);
	}

	public void addInSurveyList(Survey survey) {
		// TODO Auto-generated method stub
		surveys.add(survey);
	}
}
